package edu.ccut.saturn.tag.complex.util;

import java.util.Date;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringEscapeUtils;


public final class XmlHelper {
	private XmlHelper() {
	}

	public static final String tagProperty(String s, String s1) {
		if (StringHelper.isNotEmpty(s1)) {
			StringBuffer stringbuffer;
			(stringbuffer = new StringBuffer()).append(" " + s + "=\\\"");
			stringbuffer.append(StringEscapeUtils.escapeXml(s1));
			stringbuffer.append("\\\" ");

			return stringbuffer.toString();
		} else {
			return "";
		}
	}

	public static final String tagProperty(Object obj, String s)
			throws Exception {
		String s1 = null;
		Object obj1;
		if ((obj1 = PropertyUtils.getSimpleProperty(obj, s)) != null) {

			if ((java.lang.String.class).isInstance(obj1)) {
				s1 = obj1.toString();
			} else if ((java.lang.Boolean.class).isInstance(obj1)) {
				s1 = obj1.toString();
			} else if ((java.lang.Number.class).isInstance(obj1)) {
				s1 = obj1.toString();
			} else if ((java.util.Date.class).isInstance(obj1)) {
				s1 = Long.toString(((Date) obj1).getTime());
			} else {
				s1 = obj1.toString();
			}

		}
		return tagProperty(s, s1);
	}
	
	
	
	public static final String tagProperty1(String s, String s1) {
		if (StringHelper.isNotEmpty(s1)) {
			StringBuffer stringbuffer;
			(stringbuffer = new StringBuffer()).append(" " + s + "=\"");
			stringbuffer.append(StringEscapeUtils.escapeXml(s1));
			stringbuffer.append("\" ");

			return stringbuffer.toString();
		} else {
			return "";
		}
	}

	public static final String tagProperty1(Object obj, String s)
			throws Exception {
		String s1 = null;
		Object obj1;
		if ((obj1 = PropertyUtils.getSimpleProperty(obj, s)) != null) {

			if ((java.lang.String.class).isInstance(obj1)) {
				s1 = obj1.toString();
			} else if ((java.lang.Boolean.class).isInstance(obj1)) {
				s1 = obj1.toString();
			} else if ((java.lang.Number.class).isInstance(obj1)) {
				s1 = obj1.toString();
			} else if ((java.util.Date.class).isInstance(obj1)) {
				s1 = Long.toString(((Date) obj1).getTime());
			} else {
				s1 = obj1.toString();
			}

		}
		return tagProperty1(s, s1);
	}
	
	
	
	
	
}
